import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controller/listen_demo_controller.dart';

class ListenDemoPage extends StatelessWidget {
  const ListenDemoPage({super.key});

  @override
  Widget build(BuildContext context) {
    final ListenDemoController controller = Get.find<ListenDemoController>();
    return Scaffold(
      appBar: AppBar(
        title: const Text('GetX 监听示例'),
        leading: IconButton(
          icon: const Icon(Icons.home),
          onPressed: () => Get.offAllNamed('/'),
        ),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Obx(() => Text('count: ${controller.count.value}',
                style: const TextStyle(fontSize: 20))),
            const SizedBox(height: 10),
            Obx(() => Text('name: ${controller.name.value}',
                style: const TextStyle(fontSize: 20))),
            const SizedBox(height: 10),
            Obx(() => Text('log: ${controller.log.value}',
                style: const TextStyle(fontSize: 16, color: Colors.blue))),
            const SizedBox(height: 20),
            Row(
              children: [
                ElevatedButton(
                  onPressed: controller.increment,
                  child: const Text('count+1'),
                ),
                const SizedBox(width: 10),
                ElevatedButton(
                  onPressed: () =>
                      controller.name.value = 'Name${DateTime.now().second}',
                  child: const Text('改名'),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
 